package main.java.反射2;

import java.lang.reflect.Method;

/**
 * @Auther:Liu
 * @Testname:Test
 * @Date:2025/3/13 10:54
 */
public class Test {
    public static void main(String[] args)throws Exception {
        //得动反射对象
//        Class<?> aClass = Class.forName("反射2.Boss");
        Class<Boss> aClass = Boss.class;
        //创建类对象
        Object o = aClass.newInstance();
        //调用方法
        Method say = aClass.getDeclaredMethod("say",int.class,String.class,char.class);
        //关闭访问权限
        say.setAccessible(true);
        //反射调用对象方法
        Object i = say.invoke(o, 20, "张三",'男');
        System.out.println(i);

        //访问公共方法
        Method hi = aClass.getDeclaredMethod("hol", String.class);
        Object i1= hi.invoke(o, "去外地");
        System.out.println(i1);


        Method teach = aClass.getDeclaredMethod("teach");
        Object invoke = teach.invoke(o);
        System.out.println(invoke);
    }
}
